package judesart.app.client.widget;

import java.util.Stack;

import com.extjs.gxt.ui.client.core.XDOM;
import com.extjs.gxt.ui.client.util.Point;
import com.extjs.gxt.ui.client.util.Size;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.InfoConfig;

public class TopInfo extends Info
{
    private static Stack<TopInfo> infoStack = new Stack<TopInfo>();

    @Override
    protected Point position()
    {
        Size s = XDOM.getViewportSize();
        int left = s.width - config.width - 10 + XDOM.getBodyScrollLeft();
        int top = 10 + level * (config.height + 10) + XDOM.getBodyScrollTop();
        return new Point(left, top);
    }

    public static void display(InfoConfig config)
    {
        pop().show(config);
    }

    public static void display(String title, String text)
    {
        InfoConfig config = new InfoConfig(title, text);
        config.display = 5000;
        display(config);
    }

    private static Info pop()
    {
        Info info = infoStack.size() > 0 ? (Info) infoStack.pop() : null;
        if (info == null)
        {
            info = new TopInfo();
        }
        return info;
    }

}
